//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    recordImg: "../images/voice.png",
    stopImg: "../images/stop-disabled.png",
    startImg: "../images/record.png",
    playImg: "../images/play-disabled.png",
    temPath: ""
  },
  startRecord: function () {
    this.setData({
      recordImg: "../images/voice-recording.gif",
      startImg: "../images/recording.png",
      stopImg: "../images/stop.png"
    })
    wx.startRecord({
      success: (res) => {

      },
      complete: (res) => {
        console.log(res);
        var tempPath = res.tempFilePath;
        this.setData({
          temPath: tempPath
        })
      }
    })
  },
  stopRecord: function () {
    this.setData({
      recordImg: "../images/voice.png",
      stopImg: "../images/stop-disabled.png",
      playImg: "../images/play.png",
      startImg: "../images/record.png"
    })
    wx.stopRecord({
      success: function (res) {
        console.log(res);
      }
    })
  },
  playVoice: function () {
    this.setData({
      playImg: "../images/play-disabled.png"
    })
    wx.playVoice({
      filePath: this.data.temPath,
      duration: 60,
      success: (res) => {
        console.log(res);
      },
      complete: (res) => {
        console.log(res);
        playImg: "../images/play.png"
      }
    })
  }
})
